package com.ssh;

import org.junit.Test;

public class MySqrt_69 {
	public int mySqrt(int x) {
        if (x <= 1) {
        	return x;
        }
        int lo = 1,hi = x;
        while (lo <= hi) {
        	int mid = lo + (hi - lo) / 2;
        	int sqrt = x / mid;
        	if (sqrt == mid) {
        		return mid;
        	}else if (sqrt > mid) {
        		lo = mid + 1;
        	}else {
        		hi = mid - 1;
        	}
        }
        return lo-1;
    }@Test
	public void test () {
		System.out.println(mySqrt(2147483646));
	}
}
